import redis
from django.conf import settings
from django.db import transaction
sms_redis = redis.StrictRedis.from_url(settings.CACHES["sms_code"]["LOCATION"])
redis_client = redis.StrictRedis.from_url(settings.REDIS_URL)
REDIS_KEY = 'user_ranking'
class RedisUtils(object):
    @staticmethod
    def set_sms_code(phone, code , expire=300):
        key = f'sms_code:{phone}'
        print(f'Storing code :{code} for phone :{phone} with key : {key}')
        sms_redis.setex(f'sms_code:{phone}', expire, code)
    @staticmethod
    def get_sms_code(phone):
        code = sms_redis.get(f'sms_code:{phone}')
        return code.decode('utf-8') if code else None
    @staticmethod
    def del_sms_code(phone):
        sms_redis.delete(f'sms_code:{phone}')
